<template>
  <div v-if="partListCon">
    <!-- {{ activeBnnerIndex }}
    {{ partListCon }} -->
    <el-form ref="form" :model="partListCon" label-width="110px" size="small">
      <el-form-item label="是否显示">
        <el-switch class="zdySwith" :width="82" :value="partListCon.show" active-color="#13ce66" @change="updateInput($event, 'show')"
            inactive-color="#ffffff" active-text="显示" inactive-text="隐藏" active-value="1" inactive-value="0"></el-switch>
      </el-form-item>

      <el-form-item label="标题">
        <el-input @input="updateInput($event, 'title')" :value="partListCon.title" placeholder="请输入标题">
        </el-input>
      </el-form-item>
      <el-form-item label="副标题">
        <el-input @input="updateInput($event, 'title_en')" :value="partListCon.title_en" placeholder="请输入副标题">
        </el-input>
      </el-form-item>
      <!-- <el-form-item label="链接到">
        <el-col :span="16">
          <el-input :value="partListCon.links" @input="updateInput($event, 'links')" class="mar-input"></el-input>
          <el-input :value="partListCon.desc" @input="updateInput($event, 'desc')"></el-input>
        </el-col>
        <el-col :span="6" class="mar_lf_15">
          <LinkMenu @sendRow="getSendRow($event)" :index="0"></LinkMenu>
        </el-col>
      </el-form-item> -->
      <el-divider></el-divider>

      <el-form-item label="选择商品">
        <div class="xzshop">
          <div class="xzshopitem">
            <div class="index_img_nav img_nav addImg_menu" @click.prevent="showDio">
              <i class="el-icon-plus"></i>
            </div>
          </div>
          <div class="xzshopitem" v-for="(item, index) in partListCon.banner" :key="index">
            <div class="index_img_nav img_nav">
              <img :src="$fnc.getImgUrl(item.piclink)" alt />
            </div>
            <div class="sel_img_btn sel_img_btn-shop" style="height:auto">
              <el-input :value="index" type="number"></el-input>
            </div>
            <a href="javascript:;" @click.prevent="delshopitem(item, index)" class="alert-delete dele_banner" title="隐藏">
              <i class="el-icon-close"></i>
            </a>
          </div>
        </div>
        <!-- <el-row class="items" :gutter="24">
          <el-col :span="6" class="tr">
            <div class="index_img_nav img_nav addImg_menu" @click.prevent="showDio" style="margin:0 auto">
              <i class="el-icon-plus"></i>
            </div>
          </el-col>
          <el-col :span="6" class="tr shops_list" v-for="(item, index) in partListCon.banner" :key="index">
            <div class="index_img_nav img_nav">
              <img :src="$fnc.getImgUrl(item.piclink)" alt />
            </div>
            <div class="sel_img_btn sel_img_btn-shop" style="height:auto">
              <el-input :value="index" type="number"></el-input>
            </div>
            <a href="javascript:;" @click.prevent="delData(index)" class="alert-delete dele_banner" title="隐藏">
              <i class="el-icon-close"></i>
            </a>
          </el-col>
        </el-row> -->
      </el-form-item>
    </el-form>

    <el-dialog title="选择商品" :lock-scroll="true" :append-to-body="true" :visible.sync="show" width="1200px" style="padding:20px">
      <xzShop :show="xzshow" @isshow="closeshow" @sendShop="setId" :data="list.data" :isAddIden="false"></xzShop>
    </el-dialog>
  </div>
</template>

<script>
import uploadpic from "@/components/page/pic/up_pic";
import LinkMenu from "@/components/currency/Link_menu.vue";
import xzShop from "@/components/page/module/module_select/selshopbox";
import { mapState, mapGetters } from "vuex";
export default {
  data () {
    return {
      xzshow: false,
      currentPage1: 1,
      pageSize: 10,
      show: false,
      list: {
        data: []
      },

      style_option: [
        {
          label: "一行1个",
          value: "0"
        },
        {
          label: "一行2个",
          value: "1"
        }
      ]
    };
  },

  computed: {
    ...mapGetters(["partListConConss"]),
    ...mapState({
      active: state => state.modulePage.active,
      activeBnnerIndex: state => state.modulePage.bannerNowIndex,
      allbanner: state => state.modulePage.allbanner
    }),
    partListCon () {
      if (this.activeBnnerIndex >= 0) {
        return this.allbanner[this.activeBnnerIndex];
      } else {
        return {};
      }
    }
  },
  components: {
    uploadpic,
    LinkMenu,
    xzShop
  },
  created () { },
  mounted () { },
  methods: {
    delshopitem (item, index) {
      this.$store.commit("del_sonbanner_item", {
        key: this.activeBnnerIndex,
        index: index
      });
      var val = this.partListCon.text.replace(item.id + "@", "");

      this.$store.commit("set_sonbanner_name", {
        key: this.activeBnnerIndex,
        name: "text",
        val: val
      });
    },
    closeshow () {
      this.show = false;
      this.xzshow = false;
    },
    setId (row) {
      // this.show = false;
      // this.xzshow = false;
      console.log(row);
      var val = this.partListCon.text + row.id + "@";
      this.$store.commit("set_sonbanner_name", {
        key: this.activeBnnerIndex,
        name: "text",
        val: val
      });
      this.$store.commit("addbanner_shopitem", {
        title: row.title,
        piclink: row.piclink
      });
    },

    showDio () {
      this.show = true;
      setTimeout(() => {
        this.xzshow = true;
      }, 100);
    },
    del_banneritem (i) {
      this.$store.commit("del_sonbanner_item", {
        key: this.activeBnnerIndex,
        index: i
      });
    },
    set_banneritem_val (pic, i, name) {
      this.$store.commit("set_sonbanner_item", {
        key: this.activeBnnerIndex,
        name: name,
        index: i,
        val: pic
      });
    },

    toCheckArrIndex (i, status) {
      //排序

      var index2 = "";
      if (status == "up") {
        index2 = i - 1;
      } else {
        index2 = i + 1;
      }

      this.$store.commit("sortbanner_son", {
        key: this.activeBnnerIndex,
        index1: i,
        index2: index2,
        status: status
      });
    },
    updateInput (val, name) {
      this.$store.commit("set_sonbanner_name", {
        key: this.activeBnnerIndex,
        name: name,
        val: val
      });
    },

    getSendRow (row) {
      this.$store.dispatch("getShopsAll", { page: 1, page_size: 10 });
      var result = this.$fnc.getSendRow(row);
      var obj = {};
      obj.key = this.activeBnnerIndex;
      console.log(result);
      if (result.title != "自定义链接") {
        this.$store.commit("set_sonbanner_name", {
          key: this.activeBnnerIndex,
          name: "desc",
          val: result.desc
        });
        this.$store.commit("set_sonbanner_name", {
          key: this.activeBnnerIndex,
          name: "links",
          val: result.links
        });
      } else {
        this.$store.commit("set_sonbanner_name", {
          key: this.activeBnnerIndex,
          name: "desc",
          val: "自定义链接"
        });
        this.$store.commit("set_sonbanner_name", {
          key: this.activeBnnerIndex,
          name: "links",
          val: " "
        });
      }
    }
  },
  watch: {}
};
</script>

<style scoped lang="less"></style>
